package com.mycompany.myapp.web.rest.controller;

import com.mycompany.myapp.service.AdvertisingService;
import com.mycompany.myapp.service.dto.AdvertisingDTO;
import com.mycompany.myapp.web.rest.utils.ResultObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;

@Api(tags = {"广告管理"})
@RestController
@RequestMapping("/api")
public class AdvertisingController {

    private final AdvertisingService advertisingService;

    public AdvertisingController(AdvertisingService advertisingService) {
        this.advertisingService = advertisingService;
    }

    @ApiOperation("查入广告 RequestBody")
    @PostMapping("/davertising/insert")
    public ResultObj insertAdvertising(@RequestBody AdvertisingDTO advertisingDTO) throws URISyntaxException {
        return advertisingService.createAdvertising(advertisingDTO);
    }

    @ApiOperation("查询全部广告")
    @GetMapping("/advertising/all")
    public ResultObj getAllAdvertising() throws URISyntaxException{
        return ResultObj.back(200, advertisingService.findAll());
    }

    @ApiOperation("根据id查询广告 RequestParam")
    @GetMapping("/advertising/id")
    public ResultObj getAdvertisingById(@RequestParam Long id) throws URISyntaxException{
        return ResultObj.back(200,advertisingService.findOne(id).get());
    }

    @ApiOperation("更新广告信息 RequestBody")
    @PutMapping("/advertising/update")
    public ResultObj updateAdvertising(@RequestBody AdvertisingDTO advertisingDTO) throws URISyntaxException{
        return advertisingService.updateAdvertising(advertisingDTO);
    }

    @ApiOperation("删除广告 RequestParam")
    @DeleteMapping("/advertisting/delete/id")
    public ResultObj deleteAdvertising(@RequestParam Long id) throws URISyntaxException{
        advertisingService.delete(id);
        return ResultObj.back(200,"删除成功",null);
    }



}
